<template>
  <div>
    <div>
      <div>
        <!-- 搜索框 -->
        <div class="search">
          <div>
            <img src="../img/search.png" alt />
          </div>
          <span>搜索商品，给家人买点什么</span>
        </div>
      </div>
      <!-- 内容区 -->
      <div class="main">
        <!-- 左边 -->
        <div class="left">
          <ul>
            <li
              :class="{'active':isActive == index}"
              v-for="(item,index) in listNav"
              :key="item.id"
              @click="changeClick(item,index)"
            >{{item}}</li>
          </ul>
        </div>
        <!-- 右边 -->
        <div class="right">
          <!-- 前两个分类样式 -->
          <div class="tapOne" v-if="isOk">
            <div></div>
            <div class="tapOneMain">
              <p>
                <span></span>
                <span>热门分类</span>
                <span></span>
              </p>
              <ul class="goods">
                <li v-for="(item, index) in listdata" :key="index.id" @click="clickSkip(item.gid)">
                  <div>
                    <img :src="item.gurl" :class="{'imgCss':iscss}" alt />
                  </div>
                  <p>{{item.gtitle}}</p>
                </li>
              </ul>
            </div>
          </div>
          <!-- 珠宝钟表后面的分类样式 -->
          <div class="rightNav" v-else>
            <!-- top -->
            <div>
              <ul class="goods">
                <li
                  v-for="(item, index) in listdata.top"
                  :key="index.id"
                  @click="clickSkip(item.gid)"
                >
                  <div>
                    <img :src="item.gurl" alt />
                  </div>
                  <p>{{item.gtitle}}</p>
                </li>
              </ul>
            </div>
            <!-- main -->
            <div class="rightNavMain" v-for="(item, index) in listdata.middle" :key="index.id">
              <p class="mainTitle">
                <span>{{item.cname}}</span>
                <span>全部商品></span>
              </p>
              <ul class="goods">
                <li v-for="(item) in item.goods" :key="item.id" @click="clickSkip(item.gid)">
                  <div>
                    <img :src="item.gurl" :class="{'imgCss':iscss}" alt />
                  </div>
                  <p>{{item.gtitle}}</p>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
    <app-nav></app-nav>
  </div>
</template>
<script>
import appNav from "../components/appnav";
export default {
  components: {
    appNav
  },
  data() {
    return {
      listNav: [
        "推荐分类",
        "推荐品牌",
        "珠宝钟表",
        "酒水茗茶",
        "家用电器",
        "休闲食品",
        "粮油生鲜",
        "服饰鞋包",
        "保健营养",
        "美容化妆",
        "家居家纺",
        "厨房用具"
      ],
      isActive: 0,
      isOk: true,
      listdata: [],
      iscss: false
    };
  },
  methods: {
    async changeClick(item, index) {
      // window.console.log(index);
      this.isActive = index;
      //  window.console.log(this.isActive);
      // window.console.log(item);
      window.console.log(this.isOk);
      if (index > 1) {
        this.isOk = false;
      } else {
        this.isOk = true;
      }

      // 分类获取列表数据请求
      let { data } = await this.$axios.get(
        "http://localhost:1913/users/getlist",
        {
          params: {
            item
          }
        }
      );
      // window.console.log(data);
      this.listdata = data;
    },
    async clickSkip(id) {
      //  window.console.log(this.$route);
      this.$router.push({ path: "/detail", query: { id: id } });
    }
  },
  mounted() {
    this.changeClick("推荐分类", 0);
  }
};
</script>
<style lang="scss" scoped>
.search {
  height: 1.875rem;

  background: #f5f5f5;
  line-height: 1.875rem;
  border-radius: 0.125rem;
  margin: 0.5rem;
  text-align: center;
  display: flex;
  justify-content: center;
  div {
    // margin-left: .125rem;
    img {
      width: 0.7rem;
      height: 0.7rem;
      margin-right: 0.25rem;
    }
  }
  span {
    font-size: 0.775rem;
    color: #666;
  }
}
.main {
  display: flex;
  overflow: auto;
  flex: 1;
  .left {
    width: 25%;
    border-right: 1px solid #f5f5f5;
    ul {
      li {
        height: 1.6rem;
        line-height: 1.6rem;
        text-align: center;
        font-size: 0.9rem;
        margin: 0.8rem 0;
      }
      .active {
        color: #8909ac;
        font-size: 1.05rem;
        border-left: 0.25rem solid #8909ac;
      }
    }
  }
  .right {
    width: 75%;
    flex: 1;
    overflow: auto;

    .goods {
      margin-top: 0.025rem;
      display: flex;
      flex-wrap: wrap;
      color: #666;
      // justify-content: space-around;
      li {
        width: 33%;
        list-style: none;
        margin-top: 0.8rem;
        img {
          width: 3.125rem;
          height: 3.125rem;
        }
        .imgCss {
          border: 1px solid #f5f5f5;
          width: 3.75rem;
          height: 3.75rem;
        }
        p {
          font-size: 0.875rem;
          margin: 0.3125rem 0;
        }
      }
    }
    .tapOne {
      // background: red;
      height: 25rem;
      .tapOneMain {
        p {
          text-align: center;
          // line-height: 1.3125rem;
          position: relative;
          span {
            display: inline-block;
          }
          span:nth-of-type(2) {
            // margin:0 .1875rem;
            color: #666;
            font-size: 0.875rem;
          }
          span:nth-of-type(1),
          span:nth-of-type(3) {
            position: absolute;
            top: 1.25rem;
            left: 3.3125rem;
            width: 1.5rem;
            height: 0.0625rem;
            background: #f5f5f5;
            margin-top: -0.5625rem;
          }
          span:nth-of-type(3) {
            position: absolute;
            top: 1.25rem;
            left: 10.25rem;
          }
        }
      }
    }
    .rightNav {
      .mainTitle {
        display: flex;
        justify-content: space-between;
        margin: 0.9375rem 0;
        padding-bottom: 0.5875rem;
        font-size: 0.875rem;
        border-bottom: 0.0625rem solid #f5f5f5;
        span:nth-of-type(1) {
          margin-left: 0.625rem;
          font-weight: 600;
          color: #333;
        }
        span:nth-of-type(2) {
          margin-right: 0.625rem;

          color: #666;
        }
      }
    }
  }
}
</style>
